﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Streambolics.Gui;


namespace Streambolics.Hp41s.Gui
{
    public partial class MainDisplay : EngineUserControl
    {
        public MainDisplay ()
        {
            InitializeComponent ();
            InterceptDragDrop (label_Display);
        }

        protected override void OnDisplayChanged (EventArgs e)
        {
            base.OnDisplayChanged (e);
            if (Machine != null)
            {
                label_Display.Text = Machine.Display;
            }
            else
            {
                label_Display.Text = "-----";
            }
        }

        protected override void OnDragStart (DragStartEventArgs e)
        {
            base.OnDragStart (e);
            if (Machine != null)
            {
                inkAdapter.Clear ();
                e.DragObject = new DragData (Machine.DisplayValue, this);
            }
        }

        private void inkAdapter_InkAnalyzed (object sender, Streambolics.Tablet.InkAnalysisEventArgs e)
        {
            Compiler c = new Compiler ();
            try
            {
                Steps s = c.CompileUserInput (e.Interpretation);
                if (s != null)
                {
                    if (Machine != null)
                    {
                        Machine.Execute (s);
                    }
                    //label_Display.Text = e.Interpretation;
                    e.Accepted = true;
                    return;
                }
            }
            catch
            {
            }
        }
        

        private void menu_Clear_Click (object sender, EventArgs e)
        {
            inkAdapter.Clear ();
        }

    }
}
